Become a Pro / website · becomeapro.ai / src / app / [area] / [field] / page.tsx
| 1 | import type { Metadata } from "next"; |
| 2 | import Link from "next/link"; |
| 3 | import { notFound } from "next/navigation"; |
| 4 | import { AREAS, getArea, getField } from "@/lib/catalog"; |
| 5 | import { getFieldLessons, lessonPath } from "@/lib/lessons"; |
| 6 | import { pageMetadata } from "@/lib/seo"; |
| 7 | |
| 8 | export const dynamicParams = false; |
| 9 | |
| 10 | export function generateStaticParams() { |
| 11 | return AREAS.flatMap((a) => a.fields.map((f) => ({ area: a.slug, field: f.slug }))); |
| 12 | } |
| 13 | |
| 14 | type Props = { params: Promise<{ area: string; field: string }> }; |
| 15 | |
| 16 | export async function generateMetadata({ params }: Props): Promise<Metadata> { |
| 17 | const { area, field } = await params; |
| 18 | const f = getField(area, field); |
| 19 | return f ? pageMetadata({ title: f.name, description: f.summary }) : {}; |
| 20 | } |
| 21 | |
| 22 | export default async function FieldPage({ params }: Props) { |
| 23 | const { area: areaSlug, field: fieldSlug } = await params; |
| 24 | const area = getArea(areaSlug); |
| 25 | const field = getField(areaSlug, fieldSlug); |
| 26 | if (!area || !field) notFound(); |
| 27 | const lessons = getFieldLessons(field.slug); |
| 28 | return ( |
| 29 | <div className="page"> |
| 30 | <p className="crumbs"> |
| 31 | <Link href="/">Home</Link> / <Link href={`/${area.slug}`}>{area.name}</Link> |
| 32 | </p> |
| 33 | <h1 className="text-4xl font-bold">{field.name}</h1> |
| 34 | <p className="mt-3 text-xl">{field.summary}</p> |
| 35 | {lessons.length === 0 ? ( |
| 36 | <p className="mt-8">Lessons coming.</p> |
| 37 | ) : ( |
| 38 | <ol className="mt-8 list-decimal space-y-4 pl-6"> |
| 39 | {lessons.map((l) => ( |
| 40 | <li key={l.slug}> |
| 41 | <Link href={lessonPath(l)} className="font-semibold underline"> |
| 42 | {l.title} |
| 43 | </Link> |
| 44 | <p className="m-0 text-[16px] text-[var(--ash)]"> |
| 45 | {l.description} {l.minutes} min read. |
| 46 | </p> |
| 47 | </li> |
| 48 | ))} |
| 49 | </ol> |
| 50 | )} |
| 51 | </div> |
| 52 | ); |
| 53 | } |